#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 510;
typedef long long LL;
int arr[N];
int n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		memset(arr, 0, sizeof(arr));
		for (int i = 0; i < n; i++) {
			cin >> arr[i];
		}
		sort(arr, arr + n);
		int idx = n / 2;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans += abs(arr[i] - arr[idx]);
		}
		cout << ans << endl;
	}
	return 0;
}